package com.acmen.easyapi.service;

import com.acmen.easyapi.executor.AppExportExe;
import com.acmen.easyapi.executor.AppQueryExe;
import com.acmen.easyapi.executor.AppSyncExe;
import com.acmen.easyapi.model.App;
import com.acmen.easyapi.model.MenuTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author acmen
 */
@Service
public class AppService {
    @Autowired
    private AppSyncExe appSyncExe;
    @Autowired
    private AppQueryExe appQueryExe;
    @Autowired
    private AppExportExe appExportExe;

    public void sync(HttpServletRequest request, App app) throws IOException {
        appSyncExe.sync(request,app);
    }
    public MenuTree getApiMenuTree(String appName){
        return appQueryExe.getApiMenuTree(appName);
    }
    public String appDetail(HttpServletRequest request,String appName, ModelMap model){
        return appQueryExe.appDetail(request,appName,model);
    }

    public void export(HttpServletRequest request, HttpServletResponse response) throws IOException {
        if("pdf".equals(request.getParameter("exportType"))){
            appExportExe.exportPdf(request,response);
        }else{
            appExportExe.exportHtml(request,response);
        }
    }
    public String note(HttpServletRequest request, ModelMap model) {
        return appQueryExe.note(request,model);
    }
}
